<template>
	<view class="container">
		<uni-forms ref="form" :rules="{}">
			<uni-forms-item label="" name=""><uni-easyinput v-model="telephone" placeholder="请输入手机号" /></uni-forms-item>
			<uni-forms-item label="" name=""><uni-easyinput v-model="password" placeholder="请输入密码" type="password"/></uni-forms-item>
			<button type="primary" @click="login">登录</button>
			<navigator url="../register/register" open-type="navigate">
				<button type="default">注册</button>
			</navigator>
		</uni-forms>
	</view>
</template>

<script>
export default {
	data() {
		return {
			telephone: '12345678912',
			password: '123456'
		};
	},
	methods: {
		login() {
			uni.request({
				url: 'http://localhost:8090/foodapp/user/login',
				method: 'POST',
				data: {
					telephone: this.telephone,
					password: this.password
				},
				success: res => {
					if (res.data.success) {
						uni.setStorage({
							key: 'user',
							data: JSON.stringify(res.data.data)
						});
						uni.reLaunch({
							url:"/pages/my/my"
						})
					}else{
						uni.showToast({
							title:"登录失败",
							icon:'error'
						})
					}
				}
			});
		}
	},
	onLoad: () => {
		uni.onTabBarMidButtonTap(function(e) {
			console.log(e);
		});
	}
};
</script>

<style>
.container {
	padding: 20px;
	font-size: 14px;
	line-height: 24px;
}
</style>